<template>
  <div style="width:100vw;" class="talent-introduce">
    <!-- 头部 -->
    <!-- <div class="header-box">
      <mt-header fixed title="优才引荐">
        <router-link to="/" slot="left">
          <mt-button class="back-butt" icon="back"></mt-button>
        </router-link>
        
        <mt-button class="iconfont icon-ellipsis-vertical" slot="right"></mt-button>
      </mt-header>
    </div>-->
    <!-- 主体部分 -->
    <div class="talent-body">
      <div class="change">
        <div class="tab-btn">
          <div class="waibu">
            <mt-button :class="[externalborder,external]" @click.native="externalMethods">外部引荐</mt-button>
          </div>
          <div class="neibu">
            <mt-button :class="[insideborder,inside]" @click.native="insideMethods">内部竞聘</mt-button>
          </div>
        </div>
      </div>
      <!-- 导航区域 -->
      <div class="nav-box">
        <span :class="[recom, active]" @click="recomIt">推荐</span>
        <span :class="active1" @click="newIt">全部</span>
        <!-- <span class="position com"></span> -->
        <span class="com" @click="select">
          <span style="font-size:17px;font-weight:800;opcity:1;" class="iconfont iconsousuo"></span>
        </span>
      </div>
      <!-- 岗位列表区域 -->
      <div class="bscroll" ref="bscroll0">
        <div class="bscroll-container">
          <div
            class="position-detail"
            v-for="(items,index) in list"
            :key="index"
            @click="navegita(items.recruitment.id)"
          >
            <span class="pos">{{items.recruitment.name}}</span>
            <span class="money">{{items.recruitment.fSalary+'-'+items.recruitment.eSalary+'k'}}</span>
            <div class="xugong">{{items.company}}</div>
            <div class="tag">
              <div class="address">{{items.recruitment.city+' '+items.recruitment.address}}</div>
              <div class="time">{{items.recruitment.jobTime+'年'}}</div>
              <div
                class="edu"
              >{{items.recruitment.edu===0?'大专':items.recruitment.edu===1?'本科':items.recruitment.edu===2?'硕士':items.recruitment.edu===3?'博士':'其他'}}</div>
            </div>
            <div class="part">
              <img slot="icon" src="../../assets/talentPicture/touxiang.png" />
              <span class="caicai">{{items.name+'.'+items.deptname}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 尾部  -->
    <div class="home-footer">
      <mt-tabbar fixed v-model="selectedTab">
        <mt-tab-item id="Home">
          <!-- <img slot="icon" src="@/assets/homePicture/home1.png" /> -->
          <div slot="icon" class="iconfont home-tab-icon icontianchongxing-"></div>
          <!-- <img slot="icon" src="@/assets/homePicture/home1.png"  v-if="this.selected == 'Home'"/> -->
          首页
        </mt-tab-item>
        <mt-tab-item id="StudyCenter">
          <!-- <img slot="icon" src="@/assets/homePicture/home2.png" /> -->
          <div slot="icon" class="iconfont home-tab-icon iconwenti-shuben"></div>学习
        </mt-tab-item>
        <mt-tab-item id="Growup">
          <!-- <img slot="icon" src="@/assets/homePicture/home3.png" /> -->
          <div slot="icon" class="iconfont home-tab-icon iconxinfeng2"></div>成长
        </mt-tab-item>
        <mt-tab-item id="Things">
          <!-- <img slot="icon" src="@/assets/homePicture/home4.png" /> -->
          <div slot="icon" class="iconfont home-tab-icon iconrili"></div>办事
        </mt-tab-item>
        <mt-tab-item id="TalentIntroduce">
          <div slot="icon" class="iconfont home-tab-icon iconweibiaoti--"></div>优才
        </mt-tab-item>
      </mt-tabbar>
    </div>
  </div>
</template>
<script>
import { setText } from "../../untils/ddnavigate";
import BScroll from "better-scroll";
import { log } from 'util';
export default {
  data() {
    return {
      selectedTab: "TalentIntroduce",
      jobTime: "",
      recom: "recom",
      active: "strong",
      active1: "",
      externalborder: "externalborder",
      external: "external",
      insideborder: "insideborder",
      inside: "inside",
      params: {
        kind: 1, //外部
        page: 1,
        recommended: 1, //推荐
        pageSize: 1000
      },
      // 当前尾部选择的是 优才
      selected: 1,
      list: [], // 循环的列表
      flag: false, // 用来判断recommended
      kkind: 0,
      rrecommended: 0,
      name: ""
    };
  },
  watch: {
    selectedTab(before, after) {
      this.$router.push({ path: before });
    }
  },
  methods: {
    //筛选
    select() {
      console.log(this.$store.state.filter1,this.$store.filter);
       if (this.$store.state.filter1 == 1&&this.$store.state.filter==1) {
         this.kkind=1
         this.recommended= 1 

       }else if(this.$store.state.filter1 == 2&&this.$store.state.filter==1){
          this.kkind=1
         this.recommended= null
       }else if(this.$store.state.filter1 == 1&&this.$store.state.filter==2){
          this.kkind=0
         this.recommended= 1
       }else if(this.$store.state.filter1 == 2&&this.$store.state.filter==2){
          this.kkind=0
         this.recommended= null
       }
      this.$router.push({
        path: "/selectInfo",
        query: { kind: this.kkind, recommended: this.rrecommended }
      });
    },
    //外部推荐方法
    externalMethods() {
      if (this.$store.state.filter1 == 1) {
        this.params = {
          kind: 1, //外部
          page: 1,
          recommended: 1, //推荐
          pageSize: 1000
        };
      } else {
        this.params = {
          kind: 1, //外部
          page: 1,
          pageSize: 1000
        };
      }
      this.$store.state.filter = 1;
      this.params.kind = 1;
      this.external = "external";
      this.inside = "inside";
      this.flag = false;
      this.recomIt();
      this.getRecruitmentList();
      // console.log(this.inside)
    },
    //内部推荐人这个方法
    insideMethods() {
     if (this.$store.state.filter1 == 1) {
        this.params = {
          kind: 1, //外部
          page: 1,
          recommended: 1, //推荐
          pageSize: 1000
        };
      } else {
        this.params = {
          kind: 1, //外部
          page: 1,
          pageSize: 1000
        };
      }
      this.$store.state.filter = 2;
      this.params.kind = 0;
      this.inside = "external";
      this.external = "inside";
      if (this.flag) {
        this.recomIt();
      } else {
        // this.$delete(this.params, "recommended");
        this.getRecruitmentList();
      }
      console.log(123, this.list);
    },
    //推荐
    recomIt() {
      if (this.$store.state.filter == 1) {
        this.params = {
          kind: 1, //外部
          page: 1,
          recommended: 1, //推荐
          pageSize: 1000
        };
      } else {
        this.params = {
          kind: 0, //外部
          page: 1,
          recommended: 1, //推荐
          pageSize: 1000
        };
      }

      this.$store.state.filter1 = 1;
      this.$set(this.params, "recommended", 1);
      this.active = "strong";
      this.active1 = "";
      this.flag = false;
      this.getRecruitmentList();
    },
    //最新
    newIt() {
      if (this.$store.state.filter == 1) {
        this.params = {
          kind: 1, //外部
          page: 1,
          recommended: 1, //推荐
          pageSize: 1000
        };
      } else {
        this.params = {
          kind: 0, //外部
          page: 1,
          recommended: 1, //推荐
          pageSize: 1000
        };
      }
      this.$store.state.filter1 = 2;
      this.$delete(this.params, "recommended");
      this.active1 = "strong";
      this.active = "";
      this.flag = true;
      console.log(this.params);
      this.getRecruitmentList();
      // console.log(res)
    },
    //列表数据
    async getRecruitmentList() {
      const { data: res } = await this.$http.post(
        "/recruitment/qryRecruitmentList",
        this.params
      );
      if(res.resultCode=='100'){
         this.list = []
      }else{
          if (res.data.length > 0) {

         this.jobTime = res.data[0].recruitmentBacks.recruitment.jobTime;
        this.kkind = res.data[0].recruitmentBacks.recruitment.kind;
        this.rrecommended = res.data[0].recruitment.recruitmentBacks.recommended;
        res.data[0].recruitment.recruitmentBacks.forEach(item => {
       
          this.$set(item, "company", "徐工挖机");
        });
      }
      res.data.recruitmentBacks.forEach(item=>{
          this.$set(item, "company", "徐工挖机");
        })
      console.log(res);
     this.list = res.data.recruitmentBacks;
      this.name = res.data.recruitmentBacks[0].recruitment.name;
      console.log(this.name);
      }
      
    },
    // 跳转到详情页 根据招聘种类去判断跳转到哪个详情页
    navegita(getId) {
      if (this.params.kind == 1) {
        // console.log(this.params)
        this.$router.push({
          path: "/insideDetail",
          query: { id: getId, jobTime: this.jobTime, name: this.name }
        });
      } else {
        this.$router.push({ path: "/outsideDetail", query: { id: getId } });
      }
    },
    // initScroll(dom) {
    //   this.$nextTick(() => {
    //     let bscrollDom = this.$refs[dom];
    //     this.aBScroll = new BScroll(bscrollDom, {
    //       click: true
    //     });
    //   });
    // }
    initScroll(dom) {
      let that = this;
      that.$nextTick(() => {
        
        let bscrollDom = this.$refs[dom];
      console.log(dom);
      
        
        let bScroll = new BScroll(bscrollDom, {
          click: true,
          probeType: 2,
          bounceTime: 700, //回弹时间
          pullDownRefresh: {
            threshold: 20,
            stop: 20
          },
          pullUpLoad: {
            threshold: 0, // 当上拉距离超过50px时触发 pullingUp 事件
            stop: 20
          },
          useTransition: false // 防止iphone微信滑动卡顿
        });
        bScroll.on("pullingDown", () => {
          console.log('asd');
          
          that.loadingUp = true;
          that.loadedDown = false;
          that.params.pageNum = 1;
          setTimeout(() => {
            that.classFunction(that.params, dom, "downLoad");
          }, 1000);
          bScroll.finishPullDown();
        });
        bScroll.on("pullingUp", () => {
            console.log('asd');
          let { pageTotal } = that;
          console.log(pageTotal)
          if (that[dom].length < pageTotal) {
            that.loadingDown = true;
            that.params.pageNum++;
            setTimeout(() => {
              that.classFunction(that.params, dom, "upLoad");
            }, 1000);
          } else {
            that.loadedDown = true;
          }
          bScroll.finishPullUp();
        });
        bScroll.refresh();
      });
    },
  },
  created() {},
  mounted() {
    // 初始化滚动
     this.initScroll("bscroll0");
    // console.log(this.$store.state.filter);
    
    if (this.$store.state.filter == 1 && this.$store.state.filter1 == 1) {
      this.external = "external";
      this.inside = "inside";
      this.active = "strong";
      this.active1 = "";
      this.params = {
        kind: 1, //外部
        page: 1,
        recommended: 1, //推荐
        pageSize: 1000
      };
    } else if (
      this.$store.state.filter == 1 &&
      this.$store.state.filter1 == 2
    ) {
      this.external = "external";
      this.inside = "inside";
      this.active1 = "strong";
      this.active = "";
      this.params = {
        kind: 1, //外部
        page: 1,
        pageSize: 1000
      };
    } else if (
      this.$store.state.filter == 2 &&
      this.$store.state.filter1 == 1
    ) {
      this.inside = "external";
      this.external = "inside";
      this.active = "strong";
      this.active1 = "";
      this.params = {
        kind: 0, //外部
        page: 1,
        recommended: 1, //推荐
        pageSize: 1000
      };
    } else if (
      this.$store.state.filter == 2 &&
      this.$store.state.filter1 == 2
    ) {
      this.inside = "external";
      this.external = "inside";
      this.active1 = "strong";
      this.active = "";
      this.params = {
        kind: 0, //外部
        page: 1,
        pageSize: 1000
      };
    }

    if (this.$store.state.selectParams != "" && this.$store.state.back == 2) {
      this.params = this.$store.state.selectParams;
      this.$store.state.back = 1;
    }
    console.log(this.$store.state.filter,this.$store.state.filter1);
    
    this.getRecruitmentList();
   
    setText("优才引荐");
  }
};
</script>

<style lang="less" scoped>
.mint-button--default {
  margin-right: 0rem;
}
.bscroll-container {
  padding-bottom: 128px;
}
@import url("~@/pagecss/talent-introduce.less");
</style>